﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.GameState;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Party.PartyComponents;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements.Buildings;
using TaleWorlds.CampaignSystem.Settlements.Locations;
using TaleWorlds.CampaignSystem.Siege;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;
using TaleWorlds.SaveSystem.Load;

namespace TaleWorlds.CampaignSystem.Settlements
{
	// Token: 0x0200035A RID: 858
	public sealed class Settlement : MBObjectBase, ILocatable<Settlement>, IMapPoint, ITrackableCampaignObject, ITrackableBase, ISiegeEventSide, IMapEntity, IRandomOwner
	{
		// Token: 0x06003102 RID: 12546 RVA: 0x000CED40 File Offset: 0x000CCF40
		internal static void AutoGeneratedStaticCollectObjectsSettlement(object o, List<object> collectedObjects)
		{
			((Settlement)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06003103 RID: 12547 RVA: 0x000CED50 File Offset: 0x000CCF50
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.ClaimedBy);
			collectedObjects.Add(this.Stash);
			collectedObjects.Add(this._nextLocatable);
			collectedObjects.Add(this._settlementWallSectionHitPointsRatioList);
			collectedObjects.Add(this._boundVillages);
			collectedObjects.Add(this._lastAttackerParty);
			collectedObjects.Add(this._siegeEngineMissiles);
			collectedObjects.Add(this.Party);
			collectedObjects.Add(this.SiegeEvent);
			collectedObjects.Add(this.SettlementComponent);
			CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime(this.LastThreatTime, collectedObjects);
			collectedObjects.Add(this.SiegeEngines);
			collectedObjects.Add(this.SiegeStrategy);
			collectedObjects.Add(this.Alleys);
			collectedObjects.Add(this.LocationComplex);
		}

		// Token: 0x06003104 RID: 12548 RVA: 0x000CEE1D File Offset: 0x000CD01D
		internal static object AutoGeneratedGetMemberValueParty(object o)
		{
			return ((Settlement)o).Party;
		}

		// Token: 0x06003105 RID: 12549 RVA: 0x000CEE2A File Offset: 0x000CD02A
		internal static object AutoGeneratedGetMemberValueBribePaid(object o)
		{
			return ((Settlement)o).BribePaid;
		}

		// Token: 0x06003106 RID: 12550 RVA: 0x000CEE3C File Offset: 0x000CD03C
		internal static object AutoGeneratedGetMemberValueSiegeEvent(object o)
		{
			return ((Settlement)o).SiegeEvent;
		}

		// Token: 0x06003107 RID: 12551 RVA: 0x000CEE49 File Offset: 0x000CD049
		internal static object AutoGeneratedGetMemberValueIsActive(object o)
		{
			return ((Settlement)o).IsActive;
		}

		// Token: 0x06003108 RID: 12552 RVA: 0x000CEE5B File Offset: 0x000CD05B
		internal static object AutoGeneratedGetMemberValueNumberOfEnemiesSpottedAround(object o)
		{
			return ((Settlement)o).NumberOfEnemiesSpottedAround;
		}

		// Token: 0x06003109 RID: 12553 RVA: 0x000CEE6D File Offset: 0x000CD06D
		internal static object AutoGeneratedGetMemberValueNumberOfAlliesSpottedAround(object o)
		{
			return ((Settlement)o).NumberOfAlliesSpottedAround;
		}

		// Token: 0x0600310A RID: 12554 RVA: 0x000CEE7F File Offset: 0x000CD07F
		internal static object AutoGeneratedGetMemberValueSettlementHitPoints(object o)
		{
			return ((Settlement)o).SettlementHitPoints;
		}

		// Token: 0x0600310B RID: 12555 RVA: 0x000CEE91 File Offset: 0x000CD091
		internal static object AutoGeneratedGetMemberValueSettlementComponent(object o)
		{
			return ((Settlement)o).SettlementComponent;
		}

		// Token: 0x0600310C RID: 12556 RVA: 0x000CEE9E File Offset: 0x000CD09E
		internal static object AutoGeneratedGetMemberValueGarrisonWagePaymentLimit(object o)
		{
			return ((Settlement)o).GarrisonWagePaymentLimit;
		}

		// Token: 0x0600310D RID: 12557 RVA: 0x000CEEB0 File Offset: 0x000CD0B0
		internal static object AutoGeneratedGetMemberValueLastThreatTime(object o)
		{
			return ((Settlement)o).LastThreatTime;
		}

		// Token: 0x0600310E RID: 12558 RVA: 0x000CEEC2 File Offset: 0x000CD0C2
		internal static object AutoGeneratedGetMemberValueSiegeEngines(object o)
		{
			return ((Settlement)o).SiegeEngines;
		}

		// Token: 0x0600310F RID: 12559 RVA: 0x000CEECF File Offset: 0x000CD0CF
		internal static object AutoGeneratedGetMemberValueNumberOfTroopsKilledOnSide(object o)
		{
			return ((Settlement)o).NumberOfTroopsKilledOnSide;
		}

		// Token: 0x06003110 RID: 12560 RVA: 0x000CEEE1 File Offset: 0x000CD0E1
		internal static object AutoGeneratedGetMemberValueSiegeStrategy(object o)
		{
			return ((Settlement)o).SiegeStrategy;
		}

		// Token: 0x06003111 RID: 12561 RVA: 0x000CEEEE File Offset: 0x000CD0EE
		internal static object AutoGeneratedGetMemberValueAlleys(object o)
		{
			return ((Settlement)o).Alleys;
		}

		// Token: 0x06003112 RID: 12562 RVA: 0x000CEEFB File Offset: 0x000CD0FB
		internal static object AutoGeneratedGetMemberValueLocationComplex(object o)
		{
			return ((Settlement)o).LocationComplex;
		}

		// Token: 0x06003113 RID: 12563 RVA: 0x000CEF08 File Offset: 0x000CD108
		internal static object AutoGeneratedGetMemberValueCurrentSiegeState(object o)
		{
			return ((Settlement)o).CurrentSiegeState;
		}

		// Token: 0x06003114 RID: 12564 RVA: 0x000CEF1A File Offset: 0x000CD11A
		internal static object AutoGeneratedGetMemberValueNumberOfLordPartiesTargeting(object o)
		{
			return ((Settlement)o).NumberOfLordPartiesTargeting;
		}

		// Token: 0x06003115 RID: 12565 RVA: 0x000CEF2C File Offset: 0x000CD12C
		internal static object AutoGeneratedGetMemberValueCanBeClaimed(object o)
		{
			return ((Settlement)o).CanBeClaimed;
		}

		// Token: 0x06003116 RID: 12566 RVA: 0x000CEF3E File Offset: 0x000CD13E
		internal static object AutoGeneratedGetMemberValueClaimValue(object o)
		{
			return ((Settlement)o).ClaimValue;
		}

		// Token: 0x06003117 RID: 12567 RVA: 0x000CEF50 File Offset: 0x000CD150
		internal static object AutoGeneratedGetMemberValueClaimedBy(object o)
		{
			return ((Settlement)o).ClaimedBy;
		}

		// Token: 0x06003118 RID: 12568 RVA: 0x000CEF5D File Offset: 0x000CD15D
		internal static object AutoGeneratedGetMemberValueHasVisited(object o)
		{
			return ((Settlement)o).HasVisited;
		}

		// Token: 0x06003119 RID: 12569 RVA: 0x000CEF6F File Offset: 0x000CD16F
		internal static object AutoGeneratedGetMemberValueLastVisitTimeOfOwner(object o)
		{
			return ((Settlement)o).LastVisitTimeOfOwner;
		}

		// Token: 0x0600311A RID: 12570 RVA: 0x000CEF81 File Offset: 0x000CD181
		internal static object AutoGeneratedGetMemberValueStash(object o)
		{
			return ((Settlement)o).Stash;
		}

		// Token: 0x0600311B RID: 12571 RVA: 0x000CEF8E File Offset: 0x000CD18E
		internal static object AutoGeneratedGetMemberValue_isVisible(object o)
		{
			return ((Settlement)o)._isVisible;
		}

		// Token: 0x0600311C RID: 12572 RVA: 0x000CEFA0 File Offset: 0x000CD1A0
		internal static object AutoGeneratedGetMemberValue_nextLocatable(object o)
		{
			return ((Settlement)o)._nextLocatable;
		}

		// Token: 0x0600311D RID: 12573 RVA: 0x000CEFAD File Offset: 0x000CD1AD
		internal static object AutoGeneratedGetMemberValue_readyMilitia(object o)
		{
			return ((Settlement)o)._readyMilitia;
		}

		// Token: 0x0600311E RID: 12574 RVA: 0x000CEFBF File Offset: 0x000CD1BF
		internal static object AutoGeneratedGetMemberValue_settlementWallSectionHitPointsRatioList(object o)
		{
			return ((Settlement)o)._settlementWallSectionHitPointsRatioList;
		}

		// Token: 0x0600311F RID: 12575 RVA: 0x000CEFCC File Offset: 0x000CD1CC
		internal static object AutoGeneratedGetMemberValue_boundVillages(object o)
		{
			return ((Settlement)o)._boundVillages;
		}

		// Token: 0x06003120 RID: 12576 RVA: 0x000CEFD9 File Offset: 0x000CD1D9
		internal static object AutoGeneratedGetMemberValue_lastAttackerParty(object o)
		{
			return ((Settlement)o)._lastAttackerParty;
		}

		// Token: 0x06003121 RID: 12577 RVA: 0x000CEFE6 File Offset: 0x000CD1E6
		internal static object AutoGeneratedGetMemberValue_siegeEngineMissiles(object o)
		{
			return ((Settlement)o)._siegeEngineMissiles;
		}

		// Token: 0x17000BBD RID: 3005
		// (get) Token: 0x06003122 RID: 12578 RVA: 0x000CEFF3 File Offset: 0x000CD1F3
		// (set) Token: 0x06003123 RID: 12579 RVA: 0x000CEFFB File Offset: 0x000CD1FB
		[SaveableProperty(101)]
		public PartyBase Party { get; private set; }

		// Token: 0x17000BBE RID: 3006
		// (get) Token: 0x06003124 RID: 12580 RVA: 0x000CF004 File Offset: 0x000CD204
		public int NumberOfLordPartiesAt
		{
			get
			{
				return this._numberOfLordPartiesAt;
			}
		}

		// Token: 0x17000BBF RID: 3007
		// (get) Token: 0x06003125 RID: 12581 RVA: 0x000CF00C File Offset: 0x000CD20C
		// (set) Token: 0x06003126 RID: 12582 RVA: 0x000CF014 File Offset: 0x000CD214
		[SaveableProperty(116)]
		public int BribePaid { get; set; }

		// Token: 0x17000BC0 RID: 3008
		// (get) Token: 0x06003127 RID: 12583 RVA: 0x000CF01D File Offset: 0x000CD21D
		// (set) Token: 0x06003128 RID: 12584 RVA: 0x000CF025 File Offset: 0x000CD225
		[SaveableProperty(111)]
		public SiegeEvent SiegeEvent { get; set; }

		// Token: 0x17000BC1 RID: 3009
		// (get) Token: 0x06003129 RID: 12585 RVA: 0x000CF02E File Offset: 0x000CD22E
		// (set) Token: 0x0600312A RID: 12586 RVA: 0x000CF036 File Offset: 0x000CD236
		[SaveableProperty(112)]
		public bool IsActive { get; set; }

		// Token: 0x17000BC2 RID: 3010
		// (get) Token: 0x0600312B RID: 12587 RVA: 0x000CF03F File Offset: 0x000CD23F
		public Hero Owner
		{
			get
			{
				return this.OwnerClan.Leader;
			}
		}

		// Token: 0x17000BC3 RID: 3011
		// (get) Token: 0x0600312C RID: 12588 RVA: 0x000CF04C File Offset: 0x000CD24C
		// (set) Token: 0x0600312D RID: 12589 RVA: 0x000CF054 File Offset: 0x000CD254
		public bool IsVisible
		{
			get
			{
				return this._isVisible;
			}
			set
			{
				if (this._isVisible != value)
				{
					this._isVisible = value;
					this.Party.OnVisibilityChanged(value);
				}
			}
		}

		// Token: 0x17000BC4 RID: 3012
		// (get) Token: 0x0600312E RID: 12590 RVA: 0x000CF072 File Offset: 0x000CD272
		// (set) Token: 0x0600312F RID: 12591 RVA: 0x000CF07A File Offset: 0x000CD27A
		[CachedData]
		public bool IsInspected { get; set; }

		// Token: 0x17000BC5 RID: 3013
		// (get) Token: 0x06003130 RID: 12592 RVA: 0x000CF083 File Offset: 0x000CD283
		public int WallSectionCount
		{
			get
			{
				if (!this.IsFortification)
				{
					return 0;
				}
				return 2;
			}
		}

		// Token: 0x17000BC6 RID: 3014
		// (get) Token: 0x06003131 RID: 12593 RVA: 0x000CF090 File Offset: 0x000CD290
		// (set) Token: 0x06003132 RID: 12594 RVA: 0x000CF098 File Offset: 0x000CD298
		int ILocatable<Settlement>.LocatorNodeIndex
		{
			get
			{
				return this._locatorNodeIndex;
			}
			set
			{
				this._locatorNodeIndex = value;
			}
		}

		// Token: 0x17000BC7 RID: 3015
		// (get) Token: 0x06003133 RID: 12595 RVA: 0x000CF0A1 File Offset: 0x000CD2A1
		// (set) Token: 0x06003134 RID: 12596 RVA: 0x000CF0A9 File Offset: 0x000CD2A9
		[SaveableProperty(115)]
		public float NumberOfEnemiesSpottedAround { get; set; }

		// Token: 0x17000BC8 RID: 3016
		// (get) Token: 0x06003135 RID: 12597 RVA: 0x000CF0B2 File Offset: 0x000CD2B2
		// (set) Token: 0x06003136 RID: 12598 RVA: 0x000CF0BA File Offset: 0x000CD2BA
		[SaveableProperty(128)]
		public float NumberOfAlliesSpottedAround { get; set; }

		// Token: 0x17000BC9 RID: 3017
		// (get) Token: 0x06003137 RID: 12599 RVA: 0x000CF0C3 File Offset: 0x000CD2C3
		// (set) Token: 0x06003138 RID: 12600 RVA: 0x000CF0CB File Offset: 0x000CD2CB
		Settlement ILocatable<Settlement>.NextLocatable
		{
			get
			{
				return this._nextLocatable;
			}
			set
			{
				this._nextLocatable = value;
			}
		}

		// Token: 0x17000BCA RID: 3018
		// (get) Token: 0x06003139 RID: 12601 RVA: 0x000CF0D4 File Offset: 0x000CD2D4
		public int RandomValue
		{
			get
			{
				return this.Party.RandomValue;
			}
		}

		// Token: 0x17000BCB RID: 3019
		// (get) Token: 0x0600313A RID: 12602 RVA: 0x000CF0E1 File Offset: 0x000CD2E1
		public Vec2 GetPosition2D
		{
			get
			{
				return this.Position2D;
			}
		}

		// Token: 0x17000BCC RID: 3020
		// (get) Token: 0x0600313B RID: 12603 RVA: 0x000CF0E9 File Offset: 0x000CD2E9
		// (set) Token: 0x0600313C RID: 12604 RVA: 0x000CF128 File Offset: 0x000CD328
		public float Militia
		{
			get
			{
				return (float)((this.MilitiaPartyComponent != null && this.MilitiaPartyComponent.MobileParty.IsActive) ? this.MilitiaPartyComponent.MobileParty.Party.NumberOfAllMembers : 0) + this._readyMilitia;
			}
			set
			{
				int num = (this.MilitiaPartyComponent != null && this.MilitiaPartyComponent.MobileParty.IsActive) ? this.MilitiaPartyComponent.MobileParty.Party.NumberOfAllMembers : 0;
				this._readyMilitia = value - (float)num;
				if (this._readyMilitia < (float)(-(float)num))
				{
					this._readyMilitia = (float)(-(float)num);
				}
				if (this._readyMilitia < -1f || this._readyMilitia > 1f)
				{
					if (this.MilitiaPartyComponent != null)
					{
						this.TransferReadyMilitiasToMilitiaParty();
						return;
					}
					this.SpawnMilitiaParty();
				}
			}
		}

		// Token: 0x17000BCD RID: 3021
		// (get) Token: 0x0600313D RID: 12605 RVA: 0x000CF1B5 File Offset: 0x000CD3B5
		public MBReadOnlyList<float> SettlementWallSectionHitPointsRatioList
		{
			get
			{
				return this._settlementWallSectionHitPointsRatioList;
			}
		}

		// Token: 0x17000BCE RID: 3022
		// (get) Token: 0x0600313E RID: 12606 RVA: 0x000CF1C0 File Offset: 0x000CD3C0
		public float SettlementTotalWallHitPoints
		{
			get
			{
				float num = 0f;
				foreach (float num2 in this._settlementWallSectionHitPointsRatioList)
				{
					num += num2;
				}
				return num * this.MaxHitPointsOfOneWallSection;
			}
		}

		// Token: 0x17000BCF RID: 3023
		// (get) Token: 0x0600313F RID: 12607 RVA: 0x000CF220 File Offset: 0x000CD420
		public float MaxHitPointsOfOneWallSection
		{
			get
			{
				if (this.WallSectionCount == 0)
				{
					return 0f;
				}
				return this.MaxWallHitPoints / (float)this.WallSectionCount;
			}
		}

		// Token: 0x06003140 RID: 12608 RVA: 0x000CF23E File Offset: 0x000CD43E
		public void SetWallSectionHitPointsRatioAtIndex(int index, float hitPointsRatio)
		{
			this._settlementWallSectionHitPointsRatioList[index] = MBMath.ClampFloat(hitPointsRatio, 0f, 1f);
		}

		// Token: 0x17000BD0 RID: 3024
		// (get) Token: 0x06003141 RID: 12609 RVA: 0x000CF25C File Offset: 0x000CD45C
		// (set) Token: 0x06003142 RID: 12610 RVA: 0x000CF264 File Offset: 0x000CD464
		[SaveableProperty(121)]
		public float SettlementHitPoints { get; internal set; }

		// Token: 0x17000BD1 RID: 3025
		// (get) Token: 0x06003143 RID: 12611 RVA: 0x000CF26D File Offset: 0x000CD46D
		public float MaxWallHitPoints
		{
			get
			{
				return Campaign.Current.Models.WallHitPointCalculationModel.CalculateMaximumWallHitPoint(this.Town);
			}
		}

		// Token: 0x17000BD2 RID: 3026
		// (get) Token: 0x06003144 RID: 12612 RVA: 0x000CF289 File Offset: 0x000CD489
		public MBReadOnlyList<MobileParty> Parties
		{
			get
			{
				return this._partiesCache;
			}
		}

		// Token: 0x17000BD3 RID: 3027
		// (get) Token: 0x06003145 RID: 12613 RVA: 0x000CF291 File Offset: 0x000CD491
		public MBReadOnlyList<Hero> HeroesWithoutParty
		{
			get
			{
				return this._heroesWithoutPartyCache;
			}
		}

		// Token: 0x17000BD4 RID: 3028
		// (get) Token: 0x06003146 RID: 12614 RVA: 0x000CF299 File Offset: 0x000CD499
		public MBReadOnlyList<Hero> Notables
		{
			get
			{
				return this._notablesCache;
			}
		}

		// Token: 0x17000BD5 RID: 3029
		// (get) Token: 0x06003147 RID: 12615 RVA: 0x000CF2A1 File Offset: 0x000CD4A1
		// (set) Token: 0x06003148 RID: 12616 RVA: 0x000CF2A9 File Offset: 0x000CD4A9
		[SaveableProperty(152)]
		public SettlementComponent SettlementComponent { get; private set; }

		// Token: 0x17000BD6 RID: 3030
		// (get) Token: 0x06003149 RID: 12617 RVA: 0x000CF2B2 File Offset: 0x000CD4B2
		// (set) Token: 0x0600314A RID: 12618 RVA: 0x000CF2BC File Offset: 0x000CD4BC
		public Vec2 GatePosition
		{
			get
			{
				return this._gatePosition;
			}
			private set
			{
				this._gatePosition = value;
				Campaign campaign = Campaign.Current;
				if (campaign.MapSceneWrapper != null)
				{
					this.CurrentNavigationFace = campaign.MapSceneWrapper.GetFaceIndex(this._gatePosition);
				}
			}
		}

		// Token: 0x17000BD7 RID: 3031
		// (get) Token: 0x0600314B RID: 12619 RVA: 0x000CF2F5 File Offset: 0x000CD4F5
		// (set) Token: 0x0600314C RID: 12620 RVA: 0x000CF2FD File Offset: 0x000CD4FD
		public Vec2 Position2D
		{
			get
			{
				return this._position;
			}
			private set
			{
				this._position = value;
				Campaign.Current.SettlementLocator.UpdateLocator(this);
			}
		}

		// Token: 0x17000BD8 RID: 3032
		// (get) Token: 0x0600314D RID: 12621 RVA: 0x000CF317 File Offset: 0x000CD517
		// (set) Token: 0x0600314E RID: 12622 RVA: 0x000CF31F File Offset: 0x000CD51F
		public PathFaceRecord CurrentNavigationFace { get; private set; }

		// Token: 0x0600314F RID: 12623 RVA: 0x000CF328 File Offset: 0x000CD528
		public Vec3 GetLogicalPosition()
		{
			float z = 0f;
			Campaign.Current.MapSceneWrapper.GetHeightAtPoint(this.Position2D, ref z);
			return new Vec3(this.Position2D.x, this.Position2D.y, z, -1f);
		}

		// Token: 0x17000BD9 RID: 3033
		// (get) Token: 0x06003150 RID: 12624 RVA: 0x000CF374 File Offset: 0x000CD574
		public IFaction MapFaction
		{
			get
			{
				Town town = this.Town;
				IFaction result;
				if ((result = ((town != null) ? town.MapFaction : null)) == null)
				{
					Village village = this.Village;
					if ((result = ((village != null) ? village.Bound.MapFaction : null)) == null)
					{
						Hideout hideout = this.Hideout;
						result = (((hideout != null) ? hideout.MapFaction : null) ?? null);
					}
				}
				return result;
			}
		}

		// Token: 0x17000BDA RID: 3034
		// (get) Token: 0x06003151 RID: 12625 RVA: 0x000CF3C9 File Offset: 0x000CD5C9
		// (set) Token: 0x06003152 RID: 12626 RVA: 0x000CF3D1 File Offset: 0x000CD5D1
		public TextObject Name
		{
			get
			{
				return this._name;
			}
			set
			{
				this.SetName(value);
			}
		}

		// Token: 0x17000BDB RID: 3035
		// (get) Token: 0x06003153 RID: 12627 RVA: 0x000CF3DA File Offset: 0x000CD5DA
		// (set) Token: 0x06003154 RID: 12628 RVA: 0x000CF3E2 File Offset: 0x000CD5E2
		public TextObject EncyclopediaText { get; private set; }

		// Token: 0x17000BDC RID: 3036
		// (get) Token: 0x06003155 RID: 12629 RVA: 0x000CF3EB File Offset: 0x000CD5EB
		public string EncyclopediaLink
		{
			get
			{
				return (Campaign.Current.EncyclopediaManager.GetIdentifier(typeof(Settlement)) + "-" + base.StringId) ?? "";
			}
		}

		// Token: 0x17000BDD RID: 3037
		// (get) Token: 0x06003156 RID: 12630 RVA: 0x000CF41F File Offset: 0x000CD61F
		public TextObject EncyclopediaLinkWithName
		{
			get
			{
				return HyperlinkTexts.GetSettlementHyperlinkText(this.EncyclopediaLink, this.Name);
			}
		}

		// Token: 0x17000BDE RID: 3038
		// (get) Token: 0x06003157 RID: 12631 RVA: 0x000CF432 File Offset: 0x000CD632
		// (set) Token: 0x06003158 RID: 12632 RVA: 0x000CF43A File Offset: 0x000CD63A
		[SaveableProperty(122)]
		public int GarrisonWagePaymentLimit { get; private set; }

		// Token: 0x06003159 RID: 12633 RVA: 0x000CF443 File Offset: 0x000CD643
		public void SetGarrisonWagePaymentLimit(int limit)
		{
			this.GarrisonWagePaymentLimit = limit;
		}

		// Token: 0x17000BDF RID: 3039
		// (get) Token: 0x0600315A RID: 12634 RVA: 0x000CF44C File Offset: 0x000CD64C
		public ItemRoster ItemRoster
		{
			get
			{
				return this.Party.ItemRoster;
			}
		}

		// Token: 0x17000BE0 RID: 3040
		// (get) Token: 0x0600315B RID: 12635 RVA: 0x000CF459 File Offset: 0x000CD659
		public MBReadOnlyList<Village> BoundVillages
		{
			get
			{
				return this._boundVillages;
			}
		}

		// Token: 0x17000BE1 RID: 3041
		// (get) Token: 0x0600315C RID: 12636 RVA: 0x000CF461 File Offset: 0x000CD661
		// (set) Token: 0x0600315D RID: 12637 RVA: 0x000CF46C File Offset: 0x000CD66C
		public MobileParty LastAttackerParty
		{
			get
			{
				return this._lastAttackerParty;
			}
			set
			{
				if (this._lastAttackerParty != value)
				{
					this._lastAttackerParty = value;
					if (value != null && (this.IsFortification || this.IsVillage))
					{
						foreach (Settlement settlement in Settlement.All)
						{
							if ((settlement.IsFortification || settlement.IsVillage) && settlement.LastAttackerParty == value)
							{
								settlement.LastAttackerParty = null;
							}
						}
					}
					this._lastAttackerParty = value;
					if (this._lastAttackerParty != null)
					{
						this.LastThreatTime = CampaignTime.Now;
					}
				}
			}
		}

		// Token: 0x17000BE2 RID: 3042
		// (get) Token: 0x0600315E RID: 12638 RVA: 0x000CF518 File Offset: 0x000CD718
		// (set) Token: 0x0600315F RID: 12639 RVA: 0x000CF520 File Offset: 0x000CD720
		[SaveableProperty(137)]
		public CampaignTime LastThreatTime { get; private set; }

		// Token: 0x17000BE3 RID: 3043
		// (get) Token: 0x06003160 RID: 12640 RVA: 0x000CF529 File Offset: 0x000CD729
		// (set) Token: 0x06003161 RID: 12641 RVA: 0x000CF531 File Offset: 0x000CD731
		[SaveableProperty(149)]
		public SiegeEvent.SiegeEnginesContainer SiegeEngines { get; private set; }

		// Token: 0x17000BE4 RID: 3044
		// (get) Token: 0x06003162 RID: 12642 RVA: 0x000CF53A File Offset: 0x000CD73A
		public MBReadOnlyList<SiegeEvent.SiegeEngineMissile> SiegeEngineMissiles
		{
			get
			{
				return this._siegeEngineMissiles;
			}
		}

		// Token: 0x17000BE5 RID: 3045
		// (get) Token: 0x06003163 RID: 12643 RVA: 0x000CF542 File Offset: 0x000CD742
		public BattleSideEnum BattleSide
		{
			get
			{
				return BattleSideEnum.Defender;
			}
		}

		// Token: 0x17000BE6 RID: 3046
		// (get) Token: 0x06003164 RID: 12644 RVA: 0x000CF545 File Offset: 0x000CD745
		// (set) Token: 0x06003165 RID: 12645 RVA: 0x000CF54D File Offset: 0x000CD74D
		[SaveableProperty(150)]
		public int NumberOfTroopsKilledOnSide { get; private set; }

		// Token: 0x17000BE7 RID: 3047
		// (get) Token: 0x06003166 RID: 12646 RVA: 0x000CF556 File Offset: 0x000CD756
		// (set) Token: 0x06003167 RID: 12647 RVA: 0x000CF55E File Offset: 0x000CD75E
		[SaveableProperty(151)]
		public SiegeStrategy SiegeStrategy { get; private set; }

		// Token: 0x06003168 RID: 12648 RVA: 0x000CF567 File Offset: 0x000CD767
		public IEnumerable<PartyBase> GetInvolvedPartiesForEventType(MapEvent.BattleTypes mapEventType = MapEvent.BattleTypes.Siege)
		{
			return Campaign.Current.Models.EncounterModel.GetDefenderPartiesOfSettlement(this, mapEventType);
		}

		// Token: 0x06003169 RID: 12649 RVA: 0x000CF57F File Offset: 0x000CD77F
		public PartyBase GetNextInvolvedPartyForEventType(ref int partyIndex, MapEvent.BattleTypes mapEventType = MapEvent.BattleTypes.Siege)
		{
			return Campaign.Current.Models.EncounterModel.GetNextDefenderPartyOfSettlement(this, ref partyIndex, mapEventType);
		}

		// Token: 0x0600316A RID: 12650 RVA: 0x000CF598 File Offset: 0x000CD798
		public bool HasInvolvedPartyForEventType(PartyBase party, MapEvent.BattleTypes mapEventType = MapEvent.BattleTypes.Siege)
		{
			int num = -1;
			for (PartyBase nextDefenderPartyOfSettlement = Campaign.Current.Models.EncounterModel.GetNextDefenderPartyOfSettlement(this, ref num, mapEventType); nextDefenderPartyOfSettlement != null; nextDefenderPartyOfSettlement = Campaign.Current.Models.EncounterModel.GetNextDefenderPartyOfSettlement(this, ref num, mapEventType))
			{
				if (nextDefenderPartyOfSettlement == party)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x0600316B RID: 12651 RVA: 0x000CF5E5 File Offset: 0x000CD7E5
		internal void AddBoundVillageInternal(Village village)
		{
			this._boundVillages.Add(village);
		}

		// Token: 0x0600316C RID: 12652 RVA: 0x000CF5F3 File Offset: 0x000CD7F3
		internal void RemoveBoundVillageInternal(Village village)
		{
			this._boundVillages.Remove(village);
		}

		// Token: 0x17000BE8 RID: 3048
		// (get) Token: 0x0600316D RID: 12653 RVA: 0x000CF602 File Offset: 0x000CD802
		// (set) Token: 0x0600316E RID: 12654 RVA: 0x000CF60A File Offset: 0x000CD80A
		[SaveableProperty(133)]
		public List<Alley> Alleys { get; private set; }

		// Token: 0x0600316F RID: 12655 RVA: 0x000CF613 File Offset: 0x000CD813
		private void SetName(TextObject name)
		{
			this._name = name;
			this.SetNameAttributes();
		}

		// Token: 0x06003170 RID: 12656 RVA: 0x000CF624 File Offset: 0x000CD824
		private void SetNameAttributes()
		{
			this._name.SetTextVariable("IS_SETTLEMENT", 1);
			this._name.SetTextVariable("IS_CASTLE", this.IsCastle ? 1 : 0);
			this._name.SetTextVariable("IS_TOWN", this.IsTown ? 1 : 0);
			this._name.SetTextVariable("IS_HIDEOUT", this.IsHideout ? 1 : 0);
		}

		// Token: 0x06003171 RID: 12657 RVA: 0x000CF69C File Offset: 0x000CD89C
		private void InitSettlement()
		{
			this._partiesCache = new MBList<MobileParty>();
			this._heroesWithoutPartyCache = new MBList<Hero>();
			this._notablesCache = new MBList<Hero>();
			this._boundVillages = new MBList<Village>();
			this.SettlementHitPoints = 1f;
			this.CurrentSiegeState = Settlement.SiegeState.OnTheWalls;
			float currentTime = Campaign.CurrentTime;
			this.LastVisitTimeOfOwner = currentTime;
		}

		// Token: 0x17000BE9 RID: 3049
		// (get) Token: 0x06003172 RID: 12658 RVA: 0x000CF6F4 File Offset: 0x000CD8F4
		public bool IsTown
		{
			get
			{
				return this.Town != null && this.Town.IsTown;
			}
		}

		// Token: 0x17000BEA RID: 3050
		// (get) Token: 0x06003173 RID: 12659 RVA: 0x000CF70B File Offset: 0x000CD90B
		public bool IsCastle
		{
			get
			{
				return this.Town != null && this.Town.IsCastle;
			}
		}

		// Token: 0x17000BEB RID: 3051
		// (get) Token: 0x06003174 RID: 12660 RVA: 0x000CF722 File Offset: 0x000CD922
		public bool IsFortification
		{
			get
			{
				return this.IsTown || this.IsCastle;
			}
		}

		// Token: 0x17000BEC RID: 3052
		// (get) Token: 0x06003175 RID: 12661 RVA: 0x000CF734 File Offset: 0x000CD934
		public bool IsVillage
		{
			get
			{
				return this.Village != null;
			}
		}

		// Token: 0x17000BED RID: 3053
		// (get) Token: 0x06003176 RID: 12662 RVA: 0x000CF73F File Offset: 0x000CD93F
		public bool IsHideout
		{
			get
			{
				return this.Hideout != null;
			}
		}

		// Token: 0x17000BEE RID: 3054
		// (get) Token: 0x06003177 RID: 12663 RVA: 0x000CF74A File Offset: 0x000CD94A
		public bool IsStarving
		{
			get
			{
				return this.Town != null && this.Town.FoodStocks <= 0f;
			}
		}

		// Token: 0x17000BEF RID: 3055
		// (get) Token: 0x06003178 RID: 12664 RVA: 0x000CF76B File Offset: 0x000CD96B
		public bool IsRaided
		{
			get
			{
				return this.IsVillage && this.Village.VillageState == Village.VillageStates.Looted;
			}
		}

		// Token: 0x17000BF0 RID: 3056
		// (get) Token: 0x06003179 RID: 12665 RVA: 0x000CF785 File Offset: 0x000CD985
		public bool InRebelliousState
		{
			get
			{
				return (this.IsTown || this.IsCastle) && this.Town.InRebelliousState;
			}
		}

		// Token: 0x17000BF1 RID: 3057
		// (get) Token: 0x0600317A RID: 12666 RVA: 0x000CF7A4 File Offset: 0x000CD9A4
		public bool IsUnderRaid
		{
			get
			{
				return this.Party.MapEvent != null && this.Party.MapEvent.IsRaid;
			}
		}

		// Token: 0x17000BF2 RID: 3058
		// (get) Token: 0x0600317B RID: 12667 RVA: 0x000CF7C5 File Offset: 0x000CD9C5
		public bool IsUnderSiege
		{
			get
			{
				return this.SiegeEvent != null;
			}
		}

		// Token: 0x0600317C RID: 12668 RVA: 0x000CF7D0 File Offset: 0x000CD9D0
		public bool IsUnderRebellionAttack()
		{
			if (this.Party.MapEvent != null && this.Party.MapEvent.IsSiegeAssault)
			{
				Hero owner = this.Party.MapEvent.AttackerSide.LeaderParty.MobileParty.Party.Owner;
				if (owner != null && owner.Clan.IsRebelClan)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x0600317D RID: 12669 RVA: 0x000CF834 File Offset: 0x000CDA34
		public Settlement() : this(new TextObject("{=!}unnamed", null), null, null)
		{
		}

		// Token: 0x0600317E RID: 12670 RVA: 0x000CF84C File Offset: 0x000CDA4C
		public Settlement(TextObject name, LocationComplex locationComplex, PartyTemplateObject pt)
		{
			this._name = name;
			this._isVisible = true;
			this.IsActive = true;
			this.Party = new PartyBase(this);
			this.InitSettlement();
			this._position = Vec2.Zero;
			this.LocationComplex = locationComplex;
			this.Alleys = new List<Alley>();
			this.HasVisited = false;
			this.Stash = new ItemRoster();
		}

		// Token: 0x0600317F RID: 12671 RVA: 0x000CF8CB File Offset: 0x000CDACB
		public float GetSettlementValueForEnemyHero(Hero hero)
		{
			return Campaign.Current.Models.SettlementValueModel.CalculateSettlementValueForEnemyHero(this, hero);
		}

		// Token: 0x17000BF3 RID: 3059
		// (get) Token: 0x06003180 RID: 12672 RVA: 0x000CF8E3 File Offset: 0x000CDAE3
		// (set) Token: 0x06003181 RID: 12673 RVA: 0x000CF8EB File Offset: 0x000CDAEB
		[SaveableProperty(138)]
		public LocationComplex LocationComplex { get; private set; }

		// Token: 0x17000BF4 RID: 3060
		// (get) Token: 0x06003182 RID: 12674 RVA: 0x000CF8F4 File Offset: 0x000CDAF4
		public static Settlement CurrentSettlement
		{
			get
			{
				if (PlayerCaptivity.CaptorParty != null && PlayerCaptivity.CaptorParty.IsSettlement)
				{
					return PlayerCaptivity.CaptorParty.Settlement;
				}
				if (PlayerEncounter.EncounterSettlement != null)
				{
					return PlayerEncounter.EncounterSettlement;
				}
				if (MobileParty.MainParty.CurrentSettlement != null)
				{
					return MobileParty.MainParty.CurrentSettlement;
				}
				return null;
			}
		}

		// Token: 0x06003183 RID: 12675 RVA: 0x000CF944 File Offset: 0x000CDB44
		public float GetValue(Hero hero = null, bool countAlsoBoundedSettlements = true)
		{
			float num = 0f;
			if (this.IsVillage)
			{
				num = 100000f + this.Village.Hearth * 250f;
				num *= ((this.Village.VillageState == Village.VillageStates.Looted) ? 0.8f : ((this.Village.VillageState == Village.VillageStates.BeingRaided) ? 0.85f : (0.8f + (0.667f + 0.333f * this.Village.Settlement.SettlementHitPoints) * 0.2f)));
			}
			else if (this.IsCastle)
			{
				num = 250000f + this.Town.Prosperity * 1000f;
			}
			else if (this.IsTown)
			{
				num = 750000f + this.Town.Prosperity * 1000f;
			}
			float num2 = 1f;
			if (hero != null && hero.Clan.Settlements.Count > 0)
			{
				float num3 = MathF.Pow(Campaign.Current.Models.MapDistanceModel.GetDistance(hero.Clan.FactionMidSettlement, this) / Campaign.AverageDistanceBetweenTwoFortifications * 4f, 2f);
				num3 = MathF.Clamp(num3, 0f, 100f);
				num3 -= 16f;
				num2 *= (100f - num3) / 100f;
			}
			if (countAlsoBoundedSettlements)
			{
				foreach (Village village in this.BoundVillages)
				{
					num += village.Settlement.GetValue(hero, false);
				}
			}
			return num * num2;
		}

		// Token: 0x06003184 RID: 12676 RVA: 0x000CFAE4 File Offset: 0x000CDCE4
		public override TextObject GetName()
		{
			return this.Name;
		}

		// Token: 0x06003185 RID: 12677 RVA: 0x000CFAEC File Offset: 0x000CDCEC
		public float GetSettlementValueForFaction(IFaction faction)
		{
			return Campaign.Current.Models.SettlementValueModel.CalculateSettlementValueForFaction(this, faction);
		}

		// Token: 0x06003186 RID: 12678 RVA: 0x000CFB04 File Offset: 0x000CDD04
		public override string ToString()
		{
			return this.Name.ToString();
		}

		// Token: 0x06003187 RID: 12679 RVA: 0x000CFB14 File Offset: 0x000CDD14
		internal void AddMobileParty(MobileParty mobileParty)
		{
			if (!this._partiesCache.Contains(mobileParty))
			{
				this._partiesCache.Add(mobileParty);
				if (mobileParty.IsLordParty)
				{
					this._numberOfLordPartiesAt++;
					return;
				}
			}
			else
			{
				Debug.FailedAssert("mobileParty is already in mobileParties List!", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Settlements\\Settlement.cs", "AddMobileParty", 648);
			}
		}

		// Token: 0x06003188 RID: 12680 RVA: 0x000CFB6C File Offset: 0x000CDD6C
		internal void RemoveMobileParty(MobileParty mobileParty)
		{
			if (this._partiesCache.Contains(mobileParty))
			{
				this._partiesCache.Remove(mobileParty);
				if (mobileParty.IsLordParty)
				{
					this._numberOfLordPartiesAt--;
					return;
				}
			}
			else
			{
				Debug.FailedAssert("mobileParty is not in mobileParties List", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Settlements\\Settlement.cs", "RemoveMobileParty", 667);
			}
		}

		// Token: 0x06003189 RID: 12681 RVA: 0x000CFBC4 File Offset: 0x000CDDC4
		internal void AddHeroWithoutParty(Hero individual)
		{
			if (!this._heroesWithoutPartyCache.Contains(individual))
			{
				this._heroesWithoutPartyCache.Add(individual);
				this.CollectNotablesToCache();
				return;
			}
			Debug.FailedAssert("Notable is already in Notable List!", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Settlements\\Settlement.cs", "AddHeroWithoutParty", 686);
		}

		// Token: 0x0600318A RID: 12682 RVA: 0x000CFC00 File Offset: 0x000CDE00
		internal void RemoveHeroWithoutParty(Hero individual)
		{
			if (this._heroesWithoutPartyCache.Contains(individual))
			{
				this._heroesWithoutPartyCache.Remove(individual);
				this.CollectNotablesToCache();
				return;
			}
			Debug.FailedAssert("Notable is not in Notable List", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\Settlements\\Settlement.cs", "RemoveHeroWithoutParty", 700);
		}

		// Token: 0x0600318B RID: 12683 RVA: 0x000CFC40 File Offset: 0x000CDE40
		private void CollectNotablesToCache()
		{
			this._notablesCache.Clear();
			foreach (Hero hero in this.HeroesWithoutParty)
			{
				if (hero.IsNotable)
				{
					this._notablesCache.Add(hero);
				}
			}
		}

		// Token: 0x0600318C RID: 12684 RVA: 0x000CFCAC File Offset: 0x000CDEAC
		public override void Deserialize(MBObjectManager objectManager, XmlNode node)
		{
			bool isInitialized = base.IsInitialized;
			base.Deserialize(objectManager, node);
			this.Name = new TextObject(node.Attributes["name"].Value, null);
			this.Position2D = new Vec2((float)Convert.ToDouble(node.Attributes["posX"].Value), (float)Convert.ToDouble(node.Attributes["posY"].Value));
			this.GatePosition = this.Position2D;
			if (node.Attributes["gate_posX"] != null)
			{
				this.GatePosition = new Vec2((float)Convert.ToDouble(node.Attributes["gate_posX"].Value), (float)Convert.ToDouble(node.Attributes["gate_posY"].Value));
			}
			this.Culture = objectManager.ReadObjectReferenceFromXml<CultureObject>("culture", node);
			this.EncyclopediaText = ((node.Attributes["text"] != null) ? new TextObject(node.Attributes["text"].Value, null) : TextObject.Empty);
			if (Campaign.Current != null && Campaign.Current.MapSceneWrapper != null && !Campaign.Current.MapSceneWrapper.GetFaceIndex(this.Position2D).IsValid())
			{
				Debug.Print("Center position of settlement(" + this.GetName() + ") is invalid", 0, Debug.DebugColor.White, 17592186044416UL);
			}
			foreach (object obj in node.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Name == "Components")
				{
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						XmlNode node2 = (XmlNode)obj2;
						this.SetSettlementComponent((SettlementComponent)objectManager.CreateObjectFromXmlNode(node2));
					}
				}
				if (xmlNode.Name == "Locations")
				{
					LocationComplexTemplate complexTemplate = (LocationComplexTemplate)objectManager.ReadObjectReferenceFromXml("complex_template", typeof(LocationComplexTemplate), xmlNode);
					if (!isInitialized)
					{
						this.LocationComplex = new LocationComplex(complexTemplate);
					}
					else
					{
						this.LocationComplex.Initialize(complexTemplate);
					}
					foreach (object obj3 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj3;
						if (xmlNode2.Name == "Location")
						{
							Location locationWithId = this.LocationComplex.GetLocationWithId(xmlNode2.Attributes["id"].Value);
							if (xmlNode2.Attributes["max_prosperity"] != null)
							{
								locationWithId.ProsperityMax = int.Parse(xmlNode2.Attributes["max_prosperity"].Value);
							}
							bool flag = false;
							for (int i = 0; i < 4; i++)
							{
								string name = "scene_name" + ((i > 0) ? ("_" + i) : "");
								string text = (xmlNode2.Attributes[name] != null) ? xmlNode2.Attributes[name].Value : "";
								flag = (flag || !string.IsNullOrEmpty(text));
								locationWithId.SetSceneName(i, text);
							}
						}
					}
				}
				if (xmlNode.Name == "CommonAreas")
				{
					int num = 0;
					foreach (object obj4 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode3 = (XmlNode)obj4;
						if (xmlNode3.Name == "Area")
						{
							string value = xmlNode3.Attributes["name"].Value;
							string tag = "alley_" + (num + 1);
							if (!isInitialized)
							{
								this.Alleys.Add(new Alley(this, tag, new TextObject(value, null)));
							}
							else
							{
								this.Alleys[num].Initialize(this, tag, new TextObject(value, null));
							}
							num++;
						}
					}
					foreach (Alley alley in this.Alleys)
					{
						foreach (Alley alley2 in this.Alleys)
						{
						}
					}
				}
			}
			if (!isInitialized)
			{
				Clan clan = objectManager.ReadObjectReferenceFromXml<Clan>("owner", node);
				if (clan != null && this.Town != null)
				{
					this.Town.OwnerClan = clan;
				}
			}
			this.SetNameAttributes();
		}

		// Token: 0x0600318D RID: 12685 RVA: 0x000D0260 File Offset: 0x000CE460
		public void OnFinishLoadState()
		{
			if (this.IsFortification)
			{
				foreach (Building building in this.Town.Buildings)
				{
					if (building.BuildingType.IsDefaultProject && building.CurrentLevel != 1)
					{
						building.CurrentLevel = 1;
					}
				}
			}
			this.Party.UpdateVisibilityAndInspected(0f);
		}

		// Token: 0x0600318E RID: 12686 RVA: 0x000D02E8 File Offset: 0x000CE4E8
		public void OnGameInitialized()
		{
			Campaign campaign = Campaign.Current;
			this.CurrentNavigationFace = campaign.MapSceneWrapper.GetFaceIndex(this.GatePosition);
		}

		// Token: 0x0600318F RID: 12687 RVA: 0x000D0314 File Offset: 0x000CE514
		public void OnGameCreated()
		{
			SettlementComponent settlementComponent = this.SettlementComponent;
			if (settlementComponent != null)
			{
				settlementComponent.OnInit();
			}
			this.CreateFigure();
			this.Party.SetLevelMaskIsDirty();
			for (int i = 0; i < this.WallSectionCount; i++)
			{
				this._settlementWallSectionHitPointsRatioList.Add(1f);
			}
		}

		// Token: 0x06003190 RID: 12688 RVA: 0x000D0364 File Offset: 0x000CE564
		public void OnSessionStart()
		{
			PartyBase party = this.Party;
			if (party == null)
			{
				return;
			}
			party.SetVisualAsDirty();
		}

		// Token: 0x06003191 RID: 12689 RVA: 0x000D0376 File Offset: 0x000CE576
		[LoadInitializationCallback]
		private void OnLoad()
		{
			((ILocatable<Settlement>)this).LocatorNodeIndex = -1;
			this._partiesCache = new MBList<MobileParty>();
			this._heroesWithoutPartyCache = new MBList<Hero>();
			this._notablesCache = new MBList<Hero>();
		}

		// Token: 0x06003192 RID: 12690 RVA: 0x000D03A0 File Offset: 0x000CE5A0
		[LateLoadInitializationCallback]
		private void OnLateLoad(MetaData metaData, ObjectLoadData objectLoadData)
		{
			if (MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.2.0", 54620))
			{
				this._oldProsperityObsolete = (float)objectLoadData.GetMemberValueBySaveId(118);
			}
		}

		// Token: 0x06003193 RID: 12691 RVA: 0x000D03D7 File Offset: 0x000CE5D7
		public static Settlement Find(string idString)
		{
			return MBObjectManager.Instance.GetObject<Settlement>(idString);
		}

		// Token: 0x06003194 RID: 12692 RVA: 0x000D03E4 File Offset: 0x000CE5E4
		public static Settlement FindFirst(Func<Settlement, bool> predicate)
		{
			return Settlement.All.FirstOrDefault(predicate);
		}

		// Token: 0x06003195 RID: 12693 RVA: 0x000D03F1 File Offset: 0x000CE5F1
		public static IEnumerable<Settlement> FindAll(Func<Settlement, bool> predicate)
		{
			return Settlement.All.Where(predicate);
		}

		// Token: 0x17000BF5 RID: 3061
		// (get) Token: 0x06003196 RID: 12694 RVA: 0x000D03FE File Offset: 0x000CE5FE
		public static MBReadOnlyList<Settlement> All
		{
			get
			{
				return Campaign.Current.Settlements;
			}
		}

		// Token: 0x17000BF6 RID: 3062
		// (get) Token: 0x06003197 RID: 12695 RVA: 0x000D040A File Offset: 0x000CE60A
		public static Settlement GetFirst
		{
			get
			{
				return Settlement.All.FirstOrDefault<Settlement>();
			}
		}

		// Token: 0x06003198 RID: 12696 RVA: 0x000D0416 File Offset: 0x000CE616
		public static LocatableSearchData<Settlement> StartFindingLocatablesAroundPosition(Vec2 position, float radius)
		{
			return Campaign.Current.SettlementLocator.StartFindingLocatablesAroundPosition(position, radius);
		}

		// Token: 0x06003199 RID: 12697 RVA: 0x000D0429 File Offset: 0x000CE629
		public static Settlement FindNextLocatable(ref LocatableSearchData<Settlement> data)
		{
			return Campaign.Current.SettlementLocator.FindNextLocatable(ref data);
		}

		// Token: 0x0600319A RID: 12698 RVA: 0x000D043B File Offset: 0x000CE63B
		public void OnPlayerEncounterFinish()
		{
			LocationComplex locationComplex = this.LocationComplex;
			if (locationComplex == null)
			{
				return;
			}
			locationComplex.ClearTempCharacters();
		}

		// Token: 0x0600319B RID: 12699 RVA: 0x000D044D File Offset: 0x000CE64D
		TextObject ITrackableBase.GetName()
		{
			return this.Name;
		}

		// Token: 0x0600319C RID: 12700 RVA: 0x000D0455 File Offset: 0x000CE655
		public Vec3 GetPosition()
		{
			return this.GetLogicalPosition();
		}

		// Token: 0x0600319D RID: 12701 RVA: 0x000D0460 File Offset: 0x000CE660
		public float GetTrackDistanceToMainAgent()
		{
			return this.GetPosition().Distance(Hero.MainHero.GetPosition());
		}

		// Token: 0x0600319E RID: 12702 RVA: 0x000D0488 File Offset: 0x000CE688
		public bool CheckTracked(BasicCharacterObject basicCharacter)
		{
			return this.Notables.Any((Hero t) => t.CharacterObject == basicCharacter) || this.Party.PrisonRoster.GetTroopRoster().Any((TroopRosterElement t) => t.Character == basicCharacter) || this.Parties.Any((MobileParty p) => p.CheckTracked(basicCharacter));
		}

		// Token: 0x0600319F RID: 12703 RVA: 0x000D04F7 File Offset: 0x000CE6F7
		private void CreateFigure()
		{
		}

		// Token: 0x17000BF7 RID: 3063
		// (get) Token: 0x060031A0 RID: 12704 RVA: 0x000D04F9 File Offset: 0x000CE6F9
		// (set) Token: 0x060031A1 RID: 12705 RVA: 0x000D0501 File Offset: 0x000CE701
		[SaveableProperty(142)]
		public Settlement.SiegeState CurrentSiegeState { get; private set; }

		// Token: 0x17000BF8 RID: 3064
		// (get) Token: 0x060031A2 RID: 12706 RVA: 0x000D050C File Offset: 0x000CE70C
		public Clan OwnerClan
		{
			get
			{
				if (this.Village != null)
				{
					return this.Village.Bound.OwnerClan;
				}
				if (this.Town != null)
				{
					return this.Town.OwnerClan;
				}
				if (this.IsHideout)
				{
					return this.Hideout.MapFaction as Clan;
				}
				return null;
			}
		}

		// Token: 0x17000BF9 RID: 3065
		// (get) Token: 0x060031A3 RID: 12707 RVA: 0x000D0560 File Offset: 0x000CE760
		public bool IsAlerted
		{
			get
			{
				return this.NumberOfEnemiesSpottedAround >= 1f;
			}
		}

		// Token: 0x060031A4 RID: 12708 RVA: 0x000D0572 File Offset: 0x000CE772
		public void SetNextSiegeState()
		{
			if (this.CurrentSiegeState == Settlement.SiegeState.InTheLordsHall)
			{
				return;
			}
			this.CurrentSiegeState++;
		}

		// Token: 0x060031A5 RID: 12709 RVA: 0x000D058C File Offset: 0x000CE78C
		public void ResetSiegeState()
		{
			this.CurrentSiegeState = Settlement.SiegeState.OnTheWalls;
		}

		// Token: 0x060031A6 RID: 12710 RVA: 0x000D0598 File Offset: 0x000CE798
		public void AddGarrisonParty(bool addInitialGarrison = false)
		{
			GarrisonPartyComponent.CreateGarrisonParty(string.Concat(new string[]
			{
				"garrison_party_",
				base.StringId,
				"_",
				this.OwnerClan.StringId,
				"_1"
			}), this, addInitialGarrison);
		}

		// Token: 0x060031A7 RID: 12711 RVA: 0x000D05E8 File Offset: 0x000CE7E8
		protected override void AfterLoad()
		{
			if (this.SiegeEvent != null && this.SiegeEvent.BesiegerCamp.LeaderParty == null)
			{
				this.SiegeEvent.FinalizeSiegeEvent();
			}
			this._notablesCache = new MBList<Hero>();
			this.CollectNotablesToCache();
			this.Party.AfterLoad();
			foreach (Alley alley in this.Alleys)
			{
				alley.AfterLoad();
			}
			if (this.Town != null && this._oldProsperityObsolete > 0f)
			{
				this.Town.Prosperity = this._oldProsperityObsolete;
			}
		}

		// Token: 0x060031A8 RID: 12712 RVA: 0x000D06A0 File Offset: 0x000CE8A0
		private void SpawnMilitiaParty()
		{
			MilitiaPartyComponent.CreateMilitiaParty("militias_of_" + base.StringId + "_aaa1", this);
			this.TransferReadyMilitiasToMilitiaParty();
		}

		// Token: 0x060031A9 RID: 12713 RVA: 0x000D06C4 File Offset: 0x000CE8C4
		private void TransferReadyMilitiasToMilitiaParty()
		{
			if (this._readyMilitia >= 1f)
			{
				int num = MathF.Floor(this._readyMilitia);
				this._readyMilitia -= (float)num;
				this.AddMilitiasToParty(this.MilitiaPartyComponent.MobileParty, num);
				return;
			}
			if ((int)this._readyMilitia < -1)
			{
				int num2 = MathF.Ceiling(this._readyMilitia);
				this._readyMilitia -= (float)num2;
				Settlement.RemoveMilitiasFromParty(this.MilitiaPartyComponent.MobileParty, -num2);
			}
		}

		// Token: 0x060031AA RID: 12714 RVA: 0x000D0744 File Offset: 0x000CE944
		private void AddMilitiasToParty(MobileParty militaParty, int militiaToAdd)
		{
			float troopRatio;
			float num;
			Campaign.Current.Models.SettlementMilitiaModel.CalculateMilitiaSpawnRate(this, out troopRatio, out num);
			this.AddTroopToMilitiaParty(militaParty, this.Culture.MeleeMilitiaTroop, this.Culture.MeleeEliteMilitiaTroop, troopRatio, ref militiaToAdd);
			this.AddTroopToMilitiaParty(militaParty, this.Culture.RangedMilitiaTroop, this.Culture.RangedEliteMilitiaTroop, 1f, ref militiaToAdd);
		}

		// Token: 0x060031AB RID: 12715 RVA: 0x000D07B0 File Offset: 0x000CE9B0
		private void AddTroopToMilitiaParty(MobileParty militaParty, CharacterObject militiaTroop, CharacterObject eliteMilitiaTroop, float troopRatio, ref int numberToAddRemaining)
		{
			if (numberToAddRemaining > 0)
			{
				int num = MBRandom.RoundRandomized(troopRatio * (float)numberToAddRemaining);
				float num2 = Campaign.Current.Models.SettlementMilitiaModel.CalculateEliteMilitiaSpawnChance(this);
				for (int i = 0; i < num; i++)
				{
					if (MBRandom.RandomFloat < num2)
					{
						militaParty.MemberRoster.AddToCounts(eliteMilitiaTroop, 1, false, 0, 0, true, -1);
					}
					else
					{
						militaParty.MemberRoster.AddToCounts(militiaTroop, 1, false, 0, 0, true, -1);
					}
				}
				numberToAddRemaining -= num;
			}
		}

		// Token: 0x060031AC RID: 12716 RVA: 0x000D082C File Offset: 0x000CEA2C
		private static void RemoveMilitiasFromParty(MobileParty militaParty, int numberToRemove)
		{
			if (militaParty.MemberRoster.TotalManCount <= numberToRemove)
			{
				militaParty.MemberRoster.Clear();
				return;
			}
			float num = (float)numberToRemove / (float)militaParty.MemberRoster.TotalManCount;
			int num2 = numberToRemove;
			for (int i = 0; i < militaParty.MemberRoster.Count; i++)
			{
				int num3 = MBRandom.RoundRandomized((float)militaParty.MemberRoster.GetElementNumber(i) * num);
				if (num3 > num2)
				{
					num3 = num2;
				}
				militaParty.MemberRoster.AddToCountsAtIndex(i, -num3, 0, 0, false);
				num2 -= num3;
				if (num2 <= 0)
				{
					break;
				}
			}
			militaParty.MemberRoster.RemoveZeroCounts();
		}

		// Token: 0x060031AD RID: 12717 RVA: 0x000D08BB File Offset: 0x000CEABB
		public void SetSiegeStrategy(SiegeStrategy strategy)
		{
			this.SiegeStrategy = strategy;
		}

		// Token: 0x060031AE RID: 12718 RVA: 0x000D08C4 File Offset: 0x000CEAC4
		public void InitializeSiegeEventSide()
		{
			this.SiegeStrategy = DefaultSiegeStrategies.Custom;
			this.NumberOfTroopsKilledOnSide = 0;
			SiegeEvent.SiegeEngineConstructionProgress siegePreparations = null;
			this.SiegeEngines = new SiegeEvent.SiegeEnginesContainer(BattleSideEnum.Defender, siegePreparations);
			this._siegeEngineMissiles = new MBList<SiegeEvent.SiegeEngineMissile>();
			this.SetPrebuiltSiegeEngines();
		}

		// Token: 0x060031AF RID: 12719 RVA: 0x000D0903 File Offset: 0x000CEB03
		public void OnTroopsKilledOnSide(int killCount)
		{
			this.NumberOfTroopsKilledOnSide += killCount;
		}

		// Token: 0x060031B0 RID: 12720 RVA: 0x000D0913 File Offset: 0x000CEB13
		public void AddSiegeEngineMissile(SiegeEvent.SiegeEngineMissile missile)
		{
			this._siegeEngineMissiles.Add(missile);
		}

		// Token: 0x060031B1 RID: 12721 RVA: 0x000D0921 File Offset: 0x000CEB21
		public void RemoveDeprecatedMissiles()
		{
			this._siegeEngineMissiles.RemoveAll((SiegeEvent.SiegeEngineMissile missile) => missile.CollisionTime.IsPast);
		}

		// Token: 0x060031B2 RID: 12722 RVA: 0x000D0950 File Offset: 0x000CEB50
		private void SetPrebuiltSiegeEngines()
		{
			foreach (SiegeEngineType siegeEngine in Campaign.Current.Models.SiegeEventModel.GetPrebuiltSiegeEnginesOfSettlement(this))
			{
				float siegeEngineHitPoints = Campaign.Current.Models.SiegeEventModel.GetSiegeEngineHitPoints(this.SiegeEvent, siegeEngine, BattleSideEnum.Defender);
				SiegeEvent.SiegeEngineConstructionProgress siegeEngineConstructionProgress = new SiegeEvent.SiegeEngineConstructionProgress(siegeEngine, 1f, siegeEngineHitPoints);
				this.SiegeEngines.AddPrebuiltEngineToReserve(siegeEngineConstructionProgress);
				this.SiegeEvent.CreateSiegeObject(siegeEngineConstructionProgress, this.SiegeEvent.GetSiegeEventSide(BattleSideEnum.Defender));
			}
		}

		// Token: 0x060031B3 RID: 12723 RVA: 0x000D09F4 File Offset: 0x000CEBF4
		public void GetAttackTarget(ISiegeEventSide siegeEventSide, SiegeEngineType siegeEngine, int siegeEngineSlot, out SiegeBombardTargets targetType, out int targetIndex)
		{
			targetType = SiegeBombardTargets.None;
			targetIndex = -1;
			int num;
			float num2;
			this.SiegeEvent.FindAttackableRangedEngineWithHighestPriority(siegeEventSide, siegeEngineSlot, out num, out num2);
			if (num == -1)
			{
				return;
			}
			float num3 = num2;
			if (MBRandom.RandomFloat * num3 < num2)
			{
				targetIndex = num;
				targetType = SiegeBombardTargets.RangedEngines;
			}
		}

		// Token: 0x060031B4 RID: 12724 RVA: 0x000D0A33 File Offset: 0x000CEC33
		public void FinalizeSiegeEvent()
		{
			this.ResetSiegeState();
			this.SiegeEvent = null;
			this.Party.SetLevelMaskIsDirty();
			this.Party.SetVisualAsDirty();
		}

		// Token: 0x17000BFA RID: 3066
		// (get) Token: 0x060031B5 RID: 12725 RVA: 0x000D0A58 File Offset: 0x000CEC58
		bool IMapEntity.IsMobileEntity
		{
			get
			{
				return false;
			}
		}

		// Token: 0x17000BFB RID: 3067
		// (get) Token: 0x060031B6 RID: 12726 RVA: 0x000D0A5B File Offset: 0x000CEC5B
		bool IMapEntity.ShowCircleAroundEntity
		{
			get
			{
				return true;
			}
		}

		// Token: 0x17000BFC RID: 3068
		// (get) Token: 0x060031B7 RID: 12727 RVA: 0x000D0A5E File Offset: 0x000CEC5E
		Vec2 IMapEntity.InteractionPosition
		{
			get
			{
				return this.GatePosition;
			}
		}

		// Token: 0x060031B8 RID: 12728 RVA: 0x000D0A66 File Offset: 0x000CEC66
		bool IMapEntity.OnMapClick(bool followModifierUsed)
		{
			if (this.IsVisible)
			{
				MobileParty.MainParty.Ai.SetMoveGoToSettlement(this);
				return true;
			}
			return false;
		}

		// Token: 0x060031B9 RID: 12729 RVA: 0x000D0A83 File Offset: 0x000CEC83
		void IMapEntity.OnOpenEncyclopedia()
		{
			Campaign.Current.EncyclopediaManager.GoToLink(this.EncyclopediaLink);
		}

		// Token: 0x060031BA RID: 12730 RVA: 0x000D0A9A File Offset: 0x000CEC9A
		void IMapEntity.OnHover()
		{
			InformationManager.ShowTooltip(typeof(Settlement), new object[]
			{
				this,
				false
			});
		}

		// Token: 0x060031BB RID: 12731 RVA: 0x000D0ABE File Offset: 0x000CECBE
		bool IMapEntity.IsEnemyOf(IFaction faction)
		{
			return FactionManager.IsAtWarAgainstFaction(this.MapFaction, faction);
		}

		// Token: 0x060031BC RID: 12732 RVA: 0x000D0ACC File Offset: 0x000CECCC
		bool IMapEntity.IsAllyOf(IFaction faction)
		{
			return FactionManager.IsAlliedWithFaction(this.MapFaction, faction);
		}

		// Token: 0x060031BD RID: 12733 RVA: 0x000D0ADC File Offset: 0x000CECDC
		public void OnPartyInteraction(MobileParty mobileParty)
		{
			if (mobileParty.ShortTermTargetSettlement != null && (mobileParty.ShortTermTargetSettlement.Party.SiegeEvent == null || mobileParty == MobileParty.MainParty || mobileParty.MapFaction == mobileParty.ShortTermTargetSettlement.SiegeEvent.BesiegerCamp.LeaderParty.MapFaction) && (mobileParty.ShortTermTargetSettlement.Party.MapEvent == null || mobileParty == MobileParty.MainParty || mobileParty.MapFaction == mobileParty.ShortTermTargetSettlement.Party.MapEvent.AttackerSide.LeaderParty.MapFaction || (mobileParty.ShortTermTargetSettlement.Party.MapEvent.IsSallyOut && mobileParty.MapFaction == mobileParty.ShortTermTargetSettlement.Party.MapEvent.DefenderSide.LeaderParty.MapFaction)))
			{
				if (mobileParty == MobileParty.MainParty && (mobileParty.ShortTermTargetSettlement.Party.MapEvent == null || !mobileParty.ShortTermTargetSettlement.Party.MapEvent.IsRaid || mobileParty.ShortTermTargetSettlement.Party.MapEvent.DefenderSide.NumRemainingSimulationTroops > 0))
				{
					MapState mapState = Game.Current.GameStateManager.ActiveState as MapState;
					if (mapState != null)
					{
						mapState.OnMainPartyEncounter();
					}
				}
				if (mobileParty.ShortTermTargetSettlement.Party.MapEvent != null && mobileParty.ShortTermTargetSettlement.Party.MapEvent.IsRaid && mobileParty.DefaultBehavior == AiBehavior.RaidSettlement)
				{
					mobileParty.Ai.RethinkAtNextHourlyTick = true;
					mobileParty.Ai.SetMoveModeHold();
					return;
				}
				EncounterManager.StartSettlementEncounter(mobileParty, mobileParty.ShortTermTargetSettlement);
			}
		}

		// Token: 0x060031BE RID: 12734 RVA: 0x000D0C7B File Offset: 0x000CEE7B
		public void GetMountAndHarnessVisualIdsForPartyIcon(out string mountStringId, out string harnessStringId)
		{
			mountStringId = "";
			harnessStringId = "";
		}

		// Token: 0x060031BF RID: 12735 RVA: 0x000D0C8C File Offset: 0x000CEE8C
		public void SetSettlementComponent(SettlementComponent settlementComponent)
		{
			settlementComponent.Owner = this.Party;
			this.SettlementComponent = settlementComponent;
			if (this.SettlementComponent is Town)
			{
				this.Town = (this.SettlementComponent as Town);
				return;
			}
			if (this.SettlementComponent is Village)
			{
				this.Village = (this.SettlementComponent as Village);
				return;
			}
			if (this.SettlementComponent is Hideout)
			{
				this.Hideout = (this.SettlementComponent as Hideout);
			}
		}

		// Token: 0x04000FF0 RID: 4080
		[SaveableField(102)]
		public int NumberOfLordPartiesTargeting;

		// Token: 0x04000FF1 RID: 4081
		[CachedData]
		private int _numberOfLordPartiesAt;

		// Token: 0x04000FF2 RID: 4082
		[SaveableField(104)]
		public int CanBeClaimed;

		// Token: 0x04000FF3 RID: 4083
		[SaveableField(105)]
		public float ClaimValue;

		// Token: 0x04000FF4 RID: 4084
		[SaveableField(106)]
		public Hero ClaimedBy;

		// Token: 0x04000FF5 RID: 4085
		[SaveableField(107)]
		public bool HasVisited;

		// Token: 0x04000FF6 RID: 4086
		[SaveableField(110)]
		public float LastVisitTimeOfOwner;

		// Token: 0x04000FFA RID: 4090
		[SaveableField(113)]
		private bool _isVisible;

		// Token: 0x04000FFC RID: 4092
		[CachedData]
		private int _locatorNodeIndex;

		// Token: 0x04000FFF RID: 4095
		[SaveableField(117)]
		private Settlement _nextLocatable;

		// Token: 0x04001000 RID: 4096
		[CachedData]
		private float _oldProsperityObsolete = -1f;

		// Token: 0x04001001 RID: 4097
		[SaveableField(119)]
		private float _readyMilitia;

		// Token: 0x04001002 RID: 4098
		[SaveableField(120)]
		private MBList<float> _settlementWallSectionHitPointsRatioList = new MBList<float>();

		// Token: 0x04001004 RID: 4100
		[CachedData]
		private MBList<MobileParty> _partiesCache;

		// Token: 0x04001005 RID: 4101
		[CachedData]
		private MBList<Hero> _heroesWithoutPartyCache;

		// Token: 0x04001006 RID: 4102
		[CachedData]
		private MBList<Hero> _notablesCache;

		// Token: 0x04001008 RID: 4104
		private Vec2 _gatePosition;

		// Token: 0x04001009 RID: 4105
		private Vec2 _position;

		// Token: 0x0400100B RID: 4107
		public CultureObject Culture;

		// Token: 0x0400100C RID: 4108
		private TextObject _name;

		// Token: 0x0400100F RID: 4111
		[SaveableField(129)]
		private MBList<Village> _boundVillages;

		// Token: 0x04001010 RID: 4112
		[SaveableField(131)]
		private MobileParty _lastAttackerParty;

		// Token: 0x04001012 RID: 4114
		[SaveableField(148)]
		private MBList<SiegeEvent.SiegeEngineMissile> _siegeEngineMissiles;

		// Token: 0x04001017 RID: 4119
		public Town Town;

		// Token: 0x04001018 RID: 4120
		public Village Village;

		// Token: 0x04001019 RID: 4121
		public Hideout Hideout;

		// Token: 0x0400101C RID: 4124
		[CachedData]
		public MilitiaPartyComponent MilitiaPartyComponent;

		// Token: 0x0400101D RID: 4125
		[SaveableField(145)]
		public readonly ItemRoster Stash;

		// Token: 0x0200069D RID: 1693
		public enum SiegeState
		{
			// Token: 0x04001B8C RID: 7052
			OnTheWalls,
			// Token: 0x04001B8D RID: 7053
			InTheLordsHall,
			// Token: 0x04001B8E RID: 7054
			Invalid
		}
	}
}
